package com.fruit.util;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * 和风天气
 * @author Administrator 说明：日期处理 创建人：FH Q313596790
 * @version 2017.12.01 11:40
 */
public class WeatherUtil {

	/**
	 * weatherPost
	 * @param url url
	 * @param param param
	 * @return String
	 * @author Administrator 说明：日期处理 创建人：FH Q313596790
	 * @version 2017.12.01 11:40
	 */
	public static String weatherPost(String url, String param) {
		StringBuilder sb = new StringBuilder();
		InputStream is = null;
		BufferedReader br = null;
		try {
			// 接口地址
			URL uri = new URL(url);
			HttpURLConnection connection = (HttpURLConnection) uri.openConnection();
			connection.setRequestMethod("POST");
			connection.setReadTimeout(5000);
			connection.setConnectTimeout(10000);
			connection.setRequestProperty("accept", "*/*");
			// 发送参数
			connection.setDoOutput(true);
			PrintWriter out = new PrintWriter(connection.getOutputStream());
			out.print(param);
			out.flush();
			// 接收结果
			is = connection.getInputStream();
			br = new BufferedReader(new InputStreamReader(is));
			String line;
			// 缓冲逐行读取
			while ((line = br.readLine()) != null) {
				sb.append(line);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		return sb.toString();
	}

}
